#!/bin/bash

# 分支对应
# dev: feature/v2.0_2019
# dev_test: develop
# product: master

BRANCH_NAME=$1
DATA=$(date "+%Y%m%d_%H:%M:%S")
PROJECT_DIR="nlpservice"
BACKUPS_DIR="nlpservice"${DATA}
GIT_DIR="nlpservice_git"

# 判断是否有分支参数
if [ ! "${BRANCH_NAME}" ];then
    echo "示例：
         sh update.sh feature/v2.0_2019
         sh update.sh develop"
    exit 0
fi

cd ..

git clone -b ${BRANCH_NAME} http://git.kingdee.com/ai/nlpservice.git ${GIT_DIR}


if [ $? -eq 0 ];then
    mkdir ${BACKUPS_DIR}
    mv -f ${PROJECT_DIR}/* ${BACKUPS_DIR}
    # 将代码、logs、calfdata、拷入新的版本
    cp -r ${GIT_DIR}/. ./${PROJECT_DIR}/
    cp -r ./${BACKUPS_DIR}/logs  ./${PROJECT_DIR}/
#    cp -r ./${BACKUPS_DIR}/calfdata ./${PROJECT_DIR}/

    rm -rf ${GIT_DIR}

    echo "update success !!!"
else
    echo "update failed !!!"
fi